using System;
using System.Windows.Forms;

namespace EnablementManager
{
	/// <summary>
	/// Allows setting of wait cursor for a defined scope.  Use in a using statement.
	/// </summary>
	public class TBusyCursorScope : IDisposable
	{
		#region Initialization
		public TBusyCursorScope() : this(System.Windows.Forms.Form.ActiveForm)
		{
		}

		public TBusyCursorScope(Control pControl)
		{
			if (pControl != null)
			{
				fControl = pControl;
				fOldCursor = fControl.Cursor;
				fControl.Cursor = System.Windows.Forms.Cursors.WaitCursor;
			}
		}
		#endregion

		#region IDisposable Members

		public void Dispose()
		{
			if (fControl != null)
			{
				fControl.Cursor = fOldCursor;
			}
		}

		#endregion

		#region Private members
		private System.Windows.Forms.Cursor fOldCursor;
		private System.Windows.Forms.Control fControl;
		#endregion
	}
}
